#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QGridLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //创建六个按钮，用网格布局管理器，按照两行三列的方式排列
    QPushButton* button1 = new QPushButton("按钮1");
    QPushButton* button2 = new QPushButton("按钮2");
    QPushButton* button3 = new QPushButton("按钮3");
    QPushButton* button4 = new QPushButton("按钮4");
    QPushButton* button5 = new QPushButton("按钮5");
    QPushButton* button6 = new QPushButton("按钮6");

    //创建网格布局管理器,并添加按钮
    QGridLayout* layout = new QGridLayout();
    layout->addWidget(button1,0,0);
    layout->addWidget(button2,0,1);
    layout->addWidget(button3,0,2);
    layout->addWidget(button4,1,0);
    layout->addWidget(button5,1,1);
    layout->addWidget(button6,1,2);

    //把布局管理器添加到窗口
    this->setLayout(layout);

    //设置水平拉伸系数-->按列设置水平拉伸系数，按0：1：2的系数设置宽度比例
    layout->setColumnStretch(0,0);  //如果水平拉伸系数设置为0,则说明宽度为固定值,不参与拉伸
    layout->setColumnStretch(1,1);
    layout->setColumnStretch(2,2);

}

Widget::~Widget()
{
    delete ui;
}

